﻿package com.leqicheng.tenon.util;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.leqicheng.tenon.R;


public class BottomDialog extends Dialog implements
		android.view.View.OnClickListener {

	public interface OnBottomDialogListener {
		public void back(int mButtonNumber);
	}

	private final OnBottomDialogListener bottomDialogListener;
	private Button mBtnFirstButton;
	private Button mBtnSecondButton;
	private Button mBtnCancel;
	private String mFirstButtonText;
	private String mSecondButtonText;
	private String mCancelText;

	public BottomDialog(Context context, int theme,
			OnBottomDialogListener bottomDialogListener) {
		super(context, theme);
		this.bottomDialogListener = bottomDialogListener;
	}


    @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.widgt_bottom_dialog);
		this.mBtnFirstButton = (Button) this
				.findViewById(R.id.widgt_bottom_dialog_button1);

		this.mBtnSecondButton = (Button) this
				.findViewById(R.id.widgt_bottom_dialog_button2);

		this.mBtnCancel = (Button) this
				.findViewById(R.id.widgt_bottom_dialog_cancel);
		this.mBtnFirstButton.setText(this.mFirstButtonText);
		this.mBtnSecondButton.setText(this.mSecondButtonText);
		this.mBtnCancel.setText(this.mCancelText);
		this.mBtnFirstButton.setOnClickListener(this);
		this.mBtnSecondButton.setOnClickListener(this);
		this.mBtnCancel.setOnClickListener(this);
	}

	public void init(String firstButton, String secondButton) {
		this.mFirstButtonText = firstButton;
		this.mSecondButtonText = secondButton;
		this.mCancelText = "取消";
	}

	public void init(String firstButton, String secondButton, String mCancel) {
		this.mFirstButtonText = firstButton;
		this.mSecondButtonText = secondButton;
		this.mCancelText = mCancel;
	}

	@Override
	public void onClick(View v) {
	    if(v.getId() == R.id.widgt_bottom_dialog_button1) {
	        this.sendResult(1);
	    } else if(v.getId() == R.id.widgt_bottom_dialog_button2) {
	        this.sendResult(2);
	    } else if(v.getId() == R.id.widgt_bottom_dialog_cancel) {
	        this.dismiss();
	    }
	}

	private void sendResult(int buttonNumber) {
		this.bottomDialogListener.back(buttonNumber);
		this.dismiss();
	}

}
